Repository navigation
refactor!: rename useThemeSwitcher to useColorMode - #3
Merged
Merged
Conversation
useColorMode() returns { mode, setMode, name, names, theme }. The
ThemeProvider props are now mode, defaultMode and onModeChange, and
ThemePreference is ColorMode. useTheme() is unchanged and still returns
only the theme's tokens. ESLint now stops components and primitives
from importing useColorMode, so only app code changes the mode.
BREAKING CHANGE: useThemeSwitcher, setPreference, preference,
defaultPreference, onPreferenceChange and ThemePreference are renamed
to useColorMode, setMode, mode, defaultMode, onModeChange and ColorMode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Theme switching gets the name other libraries use:
useColorMode(). The ThemeProvider props follow it.useTheme()stays a separate hook that returns only the theme's tokens, as in MUI (useTheme/useColorScheme) and Chakra (useTheme/useColorMode).useThemeSwitcher()→{ preference, setPreference, name, names, theme }useColorMode()→{ mode, setMode, name, names, theme }<ThemeProvider preference defaultPreference onPreferenceChange><ThemeProvider mode defaultMode onModeChange>ThemePreference,ThemeSwitcherColorMode,ColorModeStateESLint now stops components and primitives from importing
useColorMode, so only app code can change the mode. I checked that it fires by importing it inCard.tsx. ADR 0005 is amended to match.Merge order: #1 adds a screen reader transcript of the theme-switching story that still reads
(preference: light). Whichever of #1 and this PR merges second needs that transcript rewritten (yarn e2e:update-transcripts).Checklist
yarn checkpasses.scaling text, and theme colors only; its states have stories (docs/accessibility.md). The only UI change is the switching story's text.
contrastRequirements.changeset (
yarn changeset).useThemeSwitcher→useColorMode, with a changeset.e2e/__screenshots__/changed, I looked at every changed image. The fourfoundations-theme--switchingimages now read "(mode: light)".or an ADR explains why. No new dependencies.
lefthook, Jest or Playwright config), the reason and an ADR are linked here.
eslint.config.mjsadds a restriction and loosens nothing (ADR 0005).Verified
yarn checkpasses: 133 UI tests at 100% coverage.yarn e2e:docker: 204 passed, including visual.